﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp3ValueConvertersWeatherForecast;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        _days.ItemsSource = Enumerable.Range(1, 10); //选择天数
    }

    private void OnDummyForecast(object sender, RoutedEventArgs e)
    {
        var data = new List<Forecast>();
        int days = (int)_days.SelectedItem;
        var rnd = Random.Shared;
        for (int i=0; i < days; i++)
        {
            double temp = rnd.NextDouble() * 40 - 10;
            var forecast = new Forecast
            {
                GeneralForecast = (GeneralForecast)rnd.Next(
                    Enum.GetNames(typeof(GeneralForecast)).Length),
                TemperatureHigh = temp + rnd.NextDouble() * 15,
                TemperatureLow = temp,
                Percipitation = rnd.Next(10) > 5
                    ? rnd.NextDouble() * 10
                    : 0
            };
            data.Add(forecast);
        }
        DataContext = data;
    }
}